<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">
    <title>幼儿园管理系统</title>
    <link rel="stylesheet" href="../res/layui/css/layui.css">
    <link rel="stylesheet" href="../res/static/css/index.css">
    <link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap.min.css}">
</head>
<body>
<!-- banner部分 -->
<div>
    <div class="layui-carousel" id="banner">
        <div carousel-item>
            <div>
                <img src="../res/static/img/child2.jpg">
            </div>
            <div>
                <img src="../res/static/img/child3.jpg">
            </div>
            <div>
                <img src="../res/static/img/child5.jpg">
            </div>
            <div>
                <img src="../res/static/img/child6.jpg">
            </div>
        </div>
    </div>
</div>
<!-- main部分 -->
<div class="main-product layui-row layui-col-space5">
    <div class="layui-col-md6" >
        <div class="layui-collapse">
            <div class="layui-colla-item">
                <h2 class="layui-colla-title">幼儿园资讯
                    <shiro:hasAnyRoles name="teacher,admin,doctor">
                        <button class="btn btn-success" style="margin-left: 20px;"  type="button" onclick="toSendInformationPage()">发布资讯</button>
                    </shiro:hasAnyRoles>
                </h2>
                <div class="layui-colla-content " id="message"></div>
            </div>
        </div>
    </div>
    <div class="layui-col-md6" >
        <div class="layui-collapse">
            <div class="layui-colla-item">
                <h2 class="layui-colla-title">家长意见
                    <shiro:hasAnyRoles name="parent">
                        <button class="btn btn-success" style="margin-left: 20px;"  type="button" onclick="toSenAdvicePage()">意见箱</button>
                    </shiro:hasAnyRoles>
                </h2>
                <div class="layui-colla-content " id="advice"></div>
            </div>
        </div>
    </div>

</div>

<script src="../res/layui/layui.js"></script>
<script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/plugin/easyui/jquery.easyui.min.js}"></script>
<script th:inline="javascript">
    $(function () {
        console.log("页面加载。。。");
        getAdviceOrMassage();

    });
    layui.config({
        base: '../res/static/js/'
    }).use('firm');

    /**
     * 获取家长意见或校园资讯
     */
    function getAdviceOrMassage() {
        $.post("/app/getAllService", function (data) {
            if (data.msg == 200) {
                for (var i = 0; i < data.adviceList.length; i++) {
                    if(data.adviceList[i].type === 3){
                        $("#message").append(" <ul class=\"layui-timeline\">\n" +
                            "            <li class=\"layui-timeline-item\">\n" +
                            "                <i class=\"layui-icon layui-timeline-axis\">&#xe63f;</i>\n" +
                            "                <div class=\"layui-timeline-content layui-text\">\n" +
                            "                    <h3 class=\"layui-timeline-title\">" + data.adviceList[i].date + "</h3>\n" +
                            "                    <ul>\n" +
                            "                        <li>" + data.adviceList[i].uname + "</li>\n" +
                            "                    </ul>\n" +
                            "                    <p>" + data.adviceList[i].adviceInfo + "</p>\n" +
                            "                </div>\n" +
                            "            </li>\n" +
                            "        </ul>");
                    }else {
                        $("#advice").append(" <ul class=\"layui-timeline\">\n" +
                            "            <li class=\"layui-timeline-item\">\n" +
                            "                <i class=\"layui-icon layui-timeline-axis\">&#xe63f;</i>\n" +
                            "                <div class=\"layui-timeline-content layui-text\">\n" +
                            "                    <h3 class=\"layui-timeline-title\">" + data.adviceList[i].date + "</h3>\n" +
                            "                    <ul>\n" +
                            "                        <li>" + data.adviceList[i].uname + "</li>\n" +
                            "                    </ul>\n" +
                            "                    <p>" + data.adviceList[i].adviceInfo + "</p>\n" +
                            "                </div>\n" +
                            "            </li>\n" +
                            "        </ul>");
                    }

                }
            } else {
                layer.msg(data.msg);
            }

        }, "json");
    }

    /**
     * 发布资讯
     */
    function toSendInformationPage() {
        var url = '/app/toSendInformation';
        parent.parent.openWindow("发布资讯", ['400px', '300px'], url);
    }

    /**
     * 意见箱
     */
    function toSenAdvicePage() {
        var url = '/app/toSendAdvice';
        parent.parent.openWindow("意见箱", ['400px', '300px'], url);
    }
</script>
</body>
</html>